<?php

namespace app\admin\controller;

use app\common\model\PanelModel;
use think\Db;

class Panel extends Intercept
{
    public function index()
    {
        if(request()->isAjax()){
            $data = (new PanelModel())->getList();
            return $data;
        }
        return $this->fetch();
    }

    public function add()
    {
        return $this->fetch();
    }


    public function edit($id)
    {
        $data = Db::name('cms_blog_panel')->where('id', $id)->select();
        $dataInfo = [];
        foreach ($data as $key=>$val){
            $dataInfo = [
                'id'=>$val['id'],
                'page_title'=>$val['page_title'],
                'rows'=>json_decode($val['rows'],true)
            ];
        }

        $this->assign('data',$dataInfo);
        return $this->fetch();
    }


    public function updateData()
    {
        if (request()->isPost()) {
            $params = input('param.');
            $data = (new PanelModel())->updateData($params);
            return $data;
        }
    }
    public function del($id)
    {
        $data = Db::name('cms_blog_panel')->where('id', $id)->delete();
        if(!empty($data)){
            return ['status' => 1, 'message' => '删除成功'];
        }
        return ['status' => 1, 'message' => '删除失败'];
    }





}